{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Count Number of Distinct Integers After Reverse Operations"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Medium"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #hash-table #math"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #哈希表 #数学"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: countDistinctIntegers"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #反转之后不同整数的数目"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个由 <strong>正</strong> 整数组成的数组 <code>nums</code> 。</p>\n",
    "\n",
    "<p>你必须取出数组中的每个整数，<strong>反转其中每个数位</strong>，并将反转后得到的数字添加到数组的末尾。这一操作只针对 <code>nums</code> 中原有的整数执行。</p>\n",
    "\n",
    "<p>返回结果数组中 <strong>不同</strong> 整数的数目。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>nums = [1,13,10,12,31]\n",
    "<strong>输出：</strong>6\n",
    "<strong>解释：</strong>反转每个数字后，结果数组是 [1,13,10,12,31,<em><strong>1,31,1,21,13</strong></em>] 。\n",
    "反转后得到的数字添加到数组的末尾并按斜体加粗表示。注意对于整数 10 ，反转之后会变成 01 ，即 1 。\n",
    "数组中不同整数的数目为 6（数字 1、10、12、13、21 和 31）。</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>nums = [2,2,2]\n",
    "<strong>输出：</strong>1\n",
    "<strong>解释：</strong>反转每个数字后，结果数组是 [2,2,2,<em><strong>2,2,2</strong></em>] 。\n",
    "数组中不同整数的数目为 1（数字 2）。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>\n",
    "\t<li><code>1 &lt;= nums[i] &lt;= 10<sup>6</sup></code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [count-number-of-distinct-integers-after-reverse-operations](https://leetcode.cn/problems/count-number-of-distinct-integers-after-reverse-operations/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [count-number-of-distinct-integers-after-reverse-operations](https://leetcode.cn/problems/count-number-of-distinct-integers-after-reverse-operations/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[1,13,10,12,31]', '[2,2,2]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        s = set()\n",
    "        for x in nums:\n",
    "            s.add(x)\n",
    "            rev = 0\n",
    "            while x:\n",
    "                rev = rev * 10 + x % 10\n",
    "                x //= 10\n",
    "            s.add(rev)\n",
    "        return len(s)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        s=set()\n",
    "        for x in nums:\n",
    "            s.add(x)\n",
    "            rev=0\n",
    "            while x:\n",
    "                rev=rev*10+x%10\n",
    "                x//=10\n",
    "            s.add(rev)\n",
    "        return len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "\n",
    "        s = set()\n",
    "\n",
    "        for x in nums:\n",
    "\n",
    "            s.add(x)\n",
    "\n",
    "            rev = 0\n",
    "\n",
    "            while x:\n",
    "\n",
    "                rev = rev * 10 + x % 10\n",
    "\n",
    "                x //= 10\n",
    "\n",
    "            s.add(rev)\n",
    "\n",
    "        return len(s)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "def func1(a):\n",
    "    total = 0\n",
    "    while a>0:\n",
    "        a,b = divmod(a,10)\n",
    "        total = total*10 +b\n",
    "    return total\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        set1 = set(nums)\n",
    "        for v in nums:\n",
    "            num = func1(v)\n",
    "            set1.add(num)\n",
    "        return len(set1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        for i in range(len(nums)):\n",
    "            j=nums[i]\n",
    "            k=int(str(j)[::-1])\n",
    "            nums.append(k)\n",
    "        return len(set(nums))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "\n",
    "        for i in range(0, len(nums)):\n",
    "            temp = 0\n",
    "            curr = nums[i]\n",
    "            while curr:\n",
    "                temp = temp * 10 + curr % 10\n",
    "                curr //= 10\n",
    "            nums.append(temp)\n",
    "        \n",
    "        return len(set(nums))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        for i in range(len(nums)):\n",
    "            x = nums[i]\n",
    "            nums.append(0)\n",
    "            while x:\n",
    "                nums[-1] = nums[-1] * 10 + x % 10\n",
    "                x //= 10\n",
    "        return len(set(nums))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        for i in range(n):\n",
    "            nums.append(int(str(nums[i])[::-1]))\n",
    "        return len(set(nums))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        for i in range(n):\n",
    "            if nums[i] >= 10:\n",
    "                new_num = int(str(nums[i])[::-1])\n",
    "                nums.append(new_num)\n",
    "        return len(set(nums))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        for i in range(len(nums)):\n",
    "            nums.append(int(str(nums[i])[::-1]))\n",
    "        return len(set(nums))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        # ans = set(nums)\n",
    "        # for i in map(str, nums):\n",
    "        #     ans.add(int(i[::-1]))\n",
    "        # return len(ans)\n",
    "        return len(set(nums + [int(i[::-1]) for i in map(str, nums)]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: list[int]) -> int:\n",
    "        def reverse(num):\n",
    "            return int(str(num)[-1::-1])\n",
    "        n = len(nums)\n",
    "        for i in range(n):\n",
    "            nums.append(reverse(nums[i]))\n",
    "        return len(set(nums))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        mark = set(nums)\n",
    "        mark1 = mark\n",
    "        for i in list(mark):\n",
    "            j = int(str(i)[::-1])\n",
    "            if j not in mark1:\n",
    "                mark1.add(j)\n",
    "        return len(mark1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        l1 = []\n",
    "        for i in range (len(nums)):\n",
    "            l1.append(int(str(nums[i])[::-1]))\n",
    "        nums = nums + l1\n",
    "        nums = set(nums)\n",
    "        return len(nums)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        aux = [int(str(each)[::-1]) for each in nums]\n",
    "        return len(set(nums+aux))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        re = [int(str(n)[::-1]) for n in nums]\n",
    "        return len(set(re + nums))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        nums = list(set(nums))\n",
    "        for i in range(len(nums)):\n",
    "            nums.append(int(str(nums[i])[::-1]))\n",
    "        return len(set(nums))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        nums1=[]\n",
    "        for n in nums:\n",
    "            n=str(n)\n",
    "            n=n[::-1]\n",
    "            n=int(n)\n",
    "            nums1.append(n)\n",
    "        nums=nums+nums1\n",
    "        return len(set(nums))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from typing import List\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        res = []\n",
    "        for num in nums:\n",
    "            res.append(num)\n",
    "            num = str(num)\n",
    "            num = num[::-1]\n",
    "            res.append(int(num))\n",
    "        res = list(set(res))\n",
    "        return len(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        target_nums = nums.copy()\n",
    "\n",
    "        for i in range(0, len(target_nums)):\n",
    "            temp = 0\n",
    "            while target_nums[i]:\n",
    "                temp = temp * 10 + target_nums[i] % 10\n",
    "                target_nums[i] //= 10\n",
    "            target_nums[i] = temp\n",
    "\n",
    "        return len(set(nums + target_nums))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        # 遍历列表\n",
    "        # 翻转每一个元素\n",
    "        # 去重\n",
    "        # 求个数\n",
    "        result = nums[:]\n",
    "        for i in nums:\n",
    "            result.append(int(str(i)[::-1]))\n",
    "        return len(set(result))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        tempset = set()\n",
    "        for num in nums:\n",
    "            tempset.add(num)\n",
    "            tempset.add(int(str(num)[::-1]))\n",
    "        return len(tempset)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        for i in range(n):\n",
    "            nums.append(int(str(nums[i])[::-1]))       \n",
    "        set1 = set(nums)\n",
    "        return len(set1)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        for i in range(n):\n",
    "            nums.append(int(str(nums[i])[::-1]))\n",
    "        return len(set(nums))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        s=set()\n",
    "        for num in nums:\n",
    "            s.add(num)\n",
    "            rev=0\n",
    "            while num:\n",
    "                rev=rev*10+num%10\n",
    "                num//=10\n",
    "            s.add(rev)\n",
    "        return len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        for i in range(n):\n",
    "            nums.append(int(str(nums[i])[::-1]))\n",
    "        set1 = set(nums)\n",
    "        return len(set1)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from collections import *\n",
    "from heapq import *\n",
    "from sys import *\n",
    "from math import *\n",
    "from itertools import *\n",
    "from functools import *\n",
    "from string import *\n",
    "from bisect import *\n",
    "from graphlib import *\n",
    "from sortedcontainers import *\n",
    "from copy import *\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        return len(set(nums + [int(str(x)[::-1]) for x in nums]))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        ans=[]\n",
    "        for i in range(len(nums)):\n",
    "            ans.append(int(str(nums[i])[::-1]))\n",
    "            #print(ans)\n",
    "\n",
    "        return len(set(nums+ ans))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        ans=[]\n",
    "        for i in nums:\n",
    "            ans.append(int(str(i)[::-1]))\n",
    "        nums.extend(ans)\n",
    "        print(nums)\n",
    "        return len(set(nums))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        nums = set(nums)\n",
    "        new_nums = set()\n",
    "        for n in nums:\n",
    "            a = list(str(n))[::-1]\n",
    "            r = int(''.join(a))\n",
    "            if r not in nums:\n",
    "                new_nums.add(r)\n",
    "        nums.update(new_nums)\n",
    "        return len(nums)\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        nums_set = set(nums)\n",
    "        ans_set = set()\n",
    "        for i in nums_set:\n",
    "            i_str = str(i)\n",
    "            i_str1 = ''.join(list(reversed(i_str)))\n",
    "            ans_set.add(i)\n",
    "            ans_set.add(int(i_str1))\n",
    "        return len(ans_set)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        # count_set = set()\n",
    "        re_num = {}\n",
    "        for num in nums:\n",
    "            str_num = str(num)\n",
    "            new_str = \"\"\n",
    "            for s in str_num:\n",
    "                new_str = s + new_str\n",
    "            new_num = int(new_str)\n",
    "            re_num[new_num] = 1\n",
    "            if new_num!=num:\n",
    "                re_num[num] = 1\n",
    "        return len(re_num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        memo = Counter()\n",
    "        for i in nums:\n",
    "            memo[i] = 1\n",
    "            if i < 10:\n",
    "                continue\n",
    "                \n",
    "            r = str(i)[::-1]\n",
    "            while r[0] == '0':\n",
    "                r = r[1:]\n",
    "            memo[int(r)] = 1\n",
    "        return len(memo)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        res=[]\n",
    "        for i in nums:\n",
    "            res.append(int(str(i)[::-1]))\n",
    "        nums+=res\n",
    "        return len(set(nums))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        res = dict()\n",
    "        for i in range(len(nums)):\n",
    "            v = nums[i]\n",
    "            res[v] = 1\n",
    "            d = 0\n",
    "            while v != 0:\n",
    "                d = d*10 + v % 10\n",
    "                v = int(v / 10)\n",
    "            res[d] = 1\n",
    "        return len(res.keys())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        # count_set = set()\n",
    "        re_num = {}\n",
    "        for num in nums:\n",
    "            str_num = str(num)\n",
    "            new_str = \"\"\n",
    "            for s in str_num:\n",
    "                new_str = s + new_str\n",
    "            new_num = int(new_str)\n",
    "            re_num[new_num] = 1\n",
    "            re_num[num] = 1\n",
    "        return len(re_num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        ret=nums.copy()\n",
    "        for i in nums:\n",
    "            ret.append(int(str(i)[::-1]))\n",
    "        return len(set(ret))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        s = set(nums)\n",
    "        del nums\n",
    "        s2 = s.copy()\n",
    "        for i in s:\n",
    "            s2.add(int(str(i)[::-1]))\n",
    "        return len(s2)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        \n",
    "        n=len(nums)\n",
    "        temp=0\n",
    "        ck=defaultdict(int)\n",
    "        for x in nums:\n",
    "            y=int(str(x)[::-1])\n",
    "            if ck[x]>0:\n",
    "                temp+=1\n",
    "            ck[x]+=1\n",
    "            if ck[y]>0:\n",
    "                temp+=1\n",
    "            ck[y]+=1\n",
    "            \n",
    "        return 2*n-temp\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        def reverse_num( n:int ):\n",
    "            re_num = 0\n",
    "            while n > 0:\n",
    "                re_num = re_num * 10 + (n%10)\n",
    "                n //= 10\n",
    "            return re_num\n",
    "        res_set = set()\n",
    "        for i in set(nums):\n",
    "            res_set.add(i)\n",
    "            res_set.add(reverse_num(i))\n",
    "        return len(res_set)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        def reverse(num):\n",
    "            x = 0\n",
    "            num = str(num)\n",
    "            n = len(num)\n",
    "            for i in range(n):\n",
    "                x = x*10 + int(num[n-i-1])\n",
    "            return x\n",
    "\n",
    "        data_ = set(nums)\n",
    "        for i in set(nums):\n",
    "            data_.add(i)\n",
    "            data_.add(reverse(i))\n",
    "\n",
    "        return len(data_)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        new = []\n",
    "        for i in nums:\n",
    "            temp = str(i)\n",
    "            temp = temp[::-1]\n",
    "            try:\n",
    "                new.append(int(temp))\n",
    "            except ValueError:\n",
    "                print(temp)\n",
    "        res = {}\n",
    "        for i,j in zip(nums,new):\n",
    "            if i not in res:\n",
    "                res[i] = True\n",
    "            if j not in res:\n",
    "                res[j] = True\n",
    "        return len(res)\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        def reverse(num):\n",
    "            x = 0\n",
    "            num = str(num)\n",
    "            n = len(num)\n",
    "            for i in range(n):\n",
    "                x = x*10 + int(num[n-i-1])\n",
    "            return x\n",
    "\n",
    "        data_ = set(nums)\n",
    "        for i in set(nums):\n",
    "            data_.add(reverse(i))\n",
    "\n",
    "        return len(data_)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        nums = set(nums)\n",
    "        data = copy.deepcopy(nums)\n",
    "        for val in nums:\n",
    "            i = 0\n",
    "            while val:\n",
    "                i = i*10 + val%10\n",
    "                val //= 10\n",
    "            data.add(i)\n",
    "        return len(data)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        xx={}\n",
    "        def dwcx(p)->int:\n",
    "            r=0\n",
    "            while p>0:\n",
    "                r=r*10+p%10\n",
    "                p=p//10\n",
    "            return r\n",
    "        for i in nums:\n",
    "            xx[i]=1\n",
    "            j=dwcx(i)\n",
    "            xx[j]=1\n",
    "        #print(xx)\n",
    "        return len(xx)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        n = len(nums)   \n",
    "        freq = Counter(nums)\n",
    "        cnt = len(freq)\n",
    "        \n",
    "        for i in range(n):\n",
    "            num = nums[i]\n",
    "            rNum = self.reverse(num)\n",
    "\n",
    "            if rNum not in freq:\n",
    "                freq[rNum] = 1\n",
    "                nums.append(rNum)\n",
    "                cnt += 1\n",
    "        \n",
    "        return cnt\n",
    "        \n",
    "    \n",
    "    def reverse(self, num):\n",
    "        numStr = str(num)\n",
    "        i, j = 0, len(numStr) - 1\n",
    "        \n",
    "        rNumStr = [c for c in numStr]\n",
    "        while i < j:\n",
    "            rNumStr[i], rNumStr[j] =  rNumStr[j], rNumStr[i]\n",
    "            i += 1\n",
    "            j -= 1\n",
    "        \n",
    "        start = 0\n",
    "        for i in range(len(rNumStr)):\n",
    "            if rNumStr[i] != '0':\n",
    "                start = i\n",
    "                break\n",
    "                \n",
    "        return int(\"\".join(rNumStr[start:]))\n",
    "    \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        # 先去重\n",
    "        nums = list(set(nums))\n",
    "        count = len(nums)\n",
    "        mp = defaultdict(int)\n",
    "        for i in nums:\n",
    "            mp[i] += 1\n",
    "            tmp = list(str(i))[::-1]\n",
    "            mp[int(\"\".join(tmp))] += 1\n",
    "        \n",
    "\n",
    "        return len(mp)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        dic = collections.Counter(nums)\n",
    "        for i in nums:\n",
    "            s = int(str(i)[::-1])\n",
    "            dic[s]+=1\n",
    "        return len(dic)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        s = Counter()\n",
    "        for num in nums:\n",
    "            s[num] += 1\n",
    "            now = int(str(num)[::-1])\n",
    "            print(now)\n",
    "            s[now] += 1\n",
    "        return len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        rec = set(nums)\n",
    "        for n in set(nums):\n",
    "            tmp = 0\n",
    "            while n != 0:\n",
    "                tmp = (tmp<<3) + (tmp<<1) + n%10\n",
    "                n //= 10\n",
    "            rec.add(tmp)\n",
    "        return len(rec)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        for i in range(len(nums)):\n",
    "            nums.append(int(str(nums[i])[::-1]))\n",
    "        HashTable={}\n",
    "        for key in nums:\n",
    "            try:\n",
    "                HashTable[key]+=1\n",
    "            except:\n",
    "                HashTable[key]=1\n",
    "        return len(HashTable)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        rec = set(nums)\n",
    "        for n in set(nums):\n",
    "            tmp = 0\n",
    "            while n != 0:\n",
    "                tmp = (tmp*10) + n%10\n",
    "                n //= 10\n",
    "            rec.add(tmp)\n",
    "        return len(rec)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        nums_set = set(nums)\n",
    "\n",
    "        for i,v in enumerate(nums_set):\n",
    "            nums.append(int(str(v)[::-1]))\n",
    "\n",
    "        return len(set(nums))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        temp=nums[:]\n",
    "        for i in nums:\n",
    "            cur=str(i)\n",
    "            cur=int(cur[::-1])\n",
    "            temp.append(cur)\n",
    "        hash_l=dict()\n",
    "        ans=0\n",
    "        for i in temp:\n",
    "            if not hash_l or i not in hash_l:\n",
    "                hash_l[i]=1\n",
    "                ans+=1\n",
    "        return ans\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        for i in range(len(nums)):\n",
    "            l = list(str(nums[i]))\n",
    "            v = int(\"\".join(l[::-1]))\n",
    "            nums.append(v)\n",
    "        print(nums)\n",
    "        cnt = Counter(nums)\n",
    "        return len(cnt.keys())\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "\n",
    "        def re(num: int) -> int:\n",
    "            res = 0\n",
    "            while num > 0:\n",
    "                res = int(num % 10) + res*10\n",
    "                num = int(num / 10)\n",
    "            return res\n",
    "        \n",
    "        res_dict = dict()\n",
    "        l = 0\n",
    "        for num in nums:\n",
    "            if res_dict.get(num) is None:\n",
    "                l += 1\n",
    "                res_dict[num] = True\n",
    "            re_num = re(num)\n",
    "            print(re_num)\n",
    "            if res_dict.get(re_num) is None:\n",
    "                l += 1\n",
    "                res_dict[re_num] = True\n",
    "        return l\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\r\n",
    "        # 需要注意最后的0的问题\r\n",
    "        def reverse(num):\r\n",
    "            ans = 0\r\n",
    "            tmp = str(num)[::-1]\r\n",
    "            n = len(tmp)\r\n",
    "            index = 0\r\n",
    "            for i in range(n):\r\n",
    "                if tmp[i] == '0':\r\n",
    "                    continue\r\n",
    "                else:\r\n",
    "                    index = i\r\n",
    "                    break\r\n",
    "            # 这里是拿到了第一个不等于0的下标\r\n",
    "            for i in range(index, n):\r\n",
    "                ans = ans * 10 + int(tmp[i])\r\n",
    "            \r\n",
    "            return ans\r\n",
    "        ans = 0\r\n",
    "        # 竟然是返回整数的不同的个数吗\r\n",
    "        for i in range(len(nums)):\r\n",
    "            nums.append(reverse(nums[i]))\r\n",
    "        print(nums)\r\n",
    "        return len(Counter(nums))\r\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        cnt = defaultdict(int)\n",
    "        def reverseNum(num):\n",
    "            return int(str(num)[::-1])\n",
    "        for i,j in enumerate(nums):\n",
    "            cnt[reverseNum(j)] += 1\n",
    "            cnt[j] += 1\n",
    "        return len(cnt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        cnt = defaultdict(int)\n",
    "        def reverseNum(num):\n",
    "            return int(str(num)[::-1])\n",
    "        \n",
    "        for i,j in enumerate(nums):\n",
    "            cnt[reverseNum(j)] += 1\n",
    "            cnt[j] += 1\n",
    "        print(cnt)\n",
    "        return len(cnt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        nums_set = set(nums)\n",
    "\n",
    "        for i,v in enumerate(nums_set):\n",
    "            nums.append(int(str(v)[::-1]))\n",
    "\n",
    "        return len(set(nums))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        st = set(nums)\n",
    "        st1 = set(nums)\n",
    "        for x in st1:\n",
    "            st.add(int(str(x)[::-1]))\n",
    "        return len(st)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def is_valid(self, num):\n",
    "        num = str(num)\n",
    "        # print(num)\n",
    "        n = len(num)\n",
    "        for i in range(n // 2):\n",
    "            if num[i] != num[n - i - 1]:\n",
    "                return False\n",
    "        return True\n",
    "        \n",
    "    def reverse_nums(self, num):\n",
    "        num = str(num)\n",
    "        \n",
    "        return int(num[::-1])\n",
    "        \n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        nums = set(nums)\n",
    "        res = set()\n",
    "        \n",
    "        for num in nums:\n",
    "            if num < 10 or self.is_valid(num):\n",
    "                continue\n",
    "            res.add(self.reverse_nums(num))\n",
    "            \n",
    "        res = list(res) + list(nums)\n",
    "        res = list(set(res))\n",
    "        \n",
    "        return len(res)\n",
    "        \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        for i in range(n):\n",
    "            nums.append(int(str(nums[i])[::-1]))\n",
    "        \n",
    "        return len(Counter(nums))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        return len(set(nums) | set(int(str(s)[::-1]) for s in nums))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        return len(set(nums) | set(int(str(x)[::-1]) for x in nums))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        return len(set(nums) | set(int(str(s)[::-1]) for s in nums))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        return len(set(nums) | set(int(str(x)[::-1]) for x in nums))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        # ans = []\n",
    "        # def num_r(num):\n",
    "        #     t = []\n",
    "        #     while num:\n",
    "        #         t.append(num%10)\n",
    "        #         num//=10\n",
    "        #     step = 1\n",
    "        #     ans = 0\n",
    "        #     while t:\n",
    "        #         ans+=step*t.pop()\n",
    "        #         step*=10\n",
    "        #     return ans\n",
    "\n",
    "        # for i in nums:\n",
    "        #     ans.append(num_r(i))       \n",
    "        # return len(set(nums+ans))\n",
    "\n",
    "        return len(set(nums) | set(int(str(i)[::-1]) for i in nums))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        return len(set(nums) | set(int(str(x)[::-1]) for x in nums))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        n=len(nums)\n",
    "        for i in range(n):\n",
    "            a=list(str(nums[i]))\n",
    "            m=reversed(a)\n",
    "            m=''.join(m)\n",
    "            nums.append(int(m))\n",
    "        \n",
    "        a=Counter(nums)\n",
    "        return len(a)\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        ret = set()\n",
    "        for n in nums:\n",
    "            s = str(n)\n",
    "            ret.add(s)\n",
    "            while n % 10 == 0:\n",
    "                n //= 10\n",
    "            ret.add(str(n)[::-1])\n",
    "        print(ret)\n",
    "        return len(ret)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        a = list(map(lambda x: int(str(x)[::-1]),nums))\n",
    "        a+=nums\n",
    "        c = Counter(a)\n",
    "        return len(list(c.keys()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        a = set(nums)\n",
    "        b = set(int(str(num)[::-1]) for num in nums)\n",
    "        return len(a | b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        #hash auto delete duplicate\n",
    "        s1=set(nums)\n",
    "        s2=set(int(str(x)[::-1] )for x in nums)\n",
    "        return len(s1|s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        step1 = [str(n) for n in nums]\n",
    "\n",
    "        reverse = []\n",
    "        for i in range(len(step1)):\n",
    "            str_rev = step1[i][::-1]\n",
    "            reverse.append(int(str_rev))\n",
    "        \n",
    "        return len(set(reverse + nums))\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# 哈希表（灵神：一次遍历，使用字符串）\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        return len(set(int(str(x)[::-1]) for x in nums) | set(nums))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        flag = set()\n",
    "        for num in nums:\n",
    "            flag.add(str(num))\n",
    "            temp = str(num)[::-1].strip(\"0\")\n",
    "            flag.add(temp)\n",
    "        \n",
    "        return len(flag)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        return len(set(nums) | set(int(str(x)[::-1]) for x in nums))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "def func1(a):\n",
    "    total = 0\n",
    "    while a>0:\n",
    "        a,b = divmod(a,10)\n",
    "        total = total*10 +b\n",
    "    return total\n",
    "class Solution:\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "        set1 = set(nums)\n",
    "        set2 =set()\n",
    "        for v in nums:\n",
    "            num = func1(v)\n",
    "            set2.add(num)\n",
    "        return len(set1.union(set2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def countDistinctIntegers(self, nums: List[int]) -> int:\n",
    "\n",
    "        return len(set(nums) | set(int(str(x)[::-1]) for x in nums))\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
